<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <link rel="icon" href="/assets/bootstrap/favicon.ico" type="image/ico">
    <link href="/assets/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="/assets/bootstrap/css/materialdesignicons.min.css" rel="stylesheet">
    <link href="/assets/bootstrap/css/style.min.css" rel="stylesheet">
</head>
<body>
<div class="container-fluid p-t-15">
    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-body">

                    <form id="edit_pwd_form" class="site-form">
                        <div class="form-group">
                            <label for="old-password">旧密码</label>
                            <input type="password" class="form-control" name="old_pwd" id="old-password" placeholder="输入账号的原登录密码">
                        </div>
                        <div class="form-group">
                            <label for="new-password">新密码</label>
                            <input type="password" class="form-control" name="new_pwd" id="new-password" placeholder="输入新的密码">
                        </div>
                        <div class="form-group">
                            <label for="confirm-password">确认新密码</label>
                            <input type="password" class="form-control" name="confirm_pwd" id="confirm-password" placeholder="请再次输入新密码">
                        </div>
                        <button type="button" class="btn btn-primary" onclick="submitForm()">提交</button>
                    </form>

                </div>
            </div>
        </div>

    </div>

</div>
<script type="text/javascript" src="/assets/bootstrap/js/jquery.min.js"></script>
<script type="text/javascript" src="/assets/bootstrap/js/bootstrap.min.js"></script>
<script src="/assets/bootstrap/js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="/assets/bootstrap/js/lightyear.js"></script>
<script type="text/javascript" src="/assets/bootstrap/js/main.min.js"></script>
<script>
    function submitForm() {
        lightyear.loading('show');  // 显示
        $.ajax({
            //几个参数需要注意一下
            type: "POST",//方法类型
            dataType: "json",//预期服务器返回的数据类型
            url: "/api/password" ,//url
            data: $('#edit_pwd_form').serialize(),
            success: function (result) {
                // console.log(result)
                lightyear.loading('hide');  // 隐藏
                if (result.code == 200) {
                    lightyear.notify('修改成功，请重新登陆~', 'success', 1000, 'mdi mdi-emoticon-happy', 'top', 'center');
                    setTimeout(function () {
                        window.parent.location.href= "/";
                    },1000)
                }else{
                    lightyear.notify('异常！'+result.msg, 'warning', 1000, 'mdi mdi-emoticon-happy', 'top', 'center');
                }
            },
            error : function(result) {
                lightyear.loading('hide');  // 隐藏
                lightyear.notify('异常！' + result.msg, 'warning', 1000, 'mdi mdi-emoticon-happy', 'top', 'center');
                setTimeout(function () {
                    location.reload();
                },1000)
            }
        });
    }
</script>

</body>
</html>